<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: helper.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage frontend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

class joomgpstracksHelper  {

    function getConfig()  {
        global $mainframe;

        $db =& JFactory::getDBO();

        $query = "SELECT * FROM #__gps_config"
                . "\n WHERE id=1";

        $db->setQuery($query);
        $object = $db->loadObject();

        return $object;
    }

}

/**
 *
 * @param string $distance
 * @return string
 */
function getMiles($distance)  {
    $miles = round($distance * 0.621, 2);
    return $miles;
}

/**
 * creates the images
 * 
 * @param string $file_tmp_name
 * @param string $ext
 * @param string $filepath
 */
function createImage($file_tmp_name, $ext, $filepath)  {

       switch ($ext)
       {
          case 'jpeg':
          case 'pjpeg':
          case 'JPG':
          case 'jpg':
             $src = ImageCreateFromJpeg($file_tmp_name);
             break;

          case 'png':
             $src = ImageCreateFromPng($file_tmp_name);
             break;

          case 'gif':
             $src = ImageCreateFromGif($file_tmp_name);
             break;

       }

        list($width,$height)=getimagesize($file_tmp_name);
        $newwidth=460;//set file width to 460
        $newheight=($height/$width)*460;//the height are set according to ratio
        $tmp=imagecreatetruecolor($newwidth,$newheight);
        imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);//resample the image

        switch ($ext)
       {
        case 'jpeg':
           case 'JPG':
        case 'jpg':
          $statusupload = imagejpeg($tmp,$filepath,100);//upload the image
          break;

        case 'png':
          $statusupload =  imagepng($tmp,$filepath,100);//upload the image
          break;

         case 'gif':
          $statusupload = imagegif($tmp,$filepath,100);//upload the image
          break;

       }
}

/**
 *
 * @param string $uid
 * @param string $username
 * @return string
 */
function getProfileLink($uid, $username)  {

    $cfg = joomgpstracksHelper::getConfig();

    switch($cfg->profile)  {

        case "cb":
            $link = "<a href=".JRoute::_('index.php?option=com_comprofiler&task=userProfile&user='.$uid)." >".$username."</a>";
            return $link;
            break;

        case "js":
            $jspath = JPATH_BASE.DS.'components'.DS.'com_community';
            include_once($jspath.DS.'libraries'.DS.'core.php');

            $link = "<a href=".CRoute::_('index.php?option=com_community&view=profile&userid='.$uid)." >".$username."</a>";
            return $link;
            break;

        case "ku":
            $link = "<a href=".JRoute::_('index.php?option=com_kunena&func=fbprofile&userid='.$uid)." >".$username."</a>";
            return $link;
            break;

        case "0":
            $link = $username;
            return $link;
            break;

    }
}


?>
